package com.cs.service.goods.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cs.mapper.GoodsMapper;
import com.cs.pojo.Goods;
import com.cs.pojo.User;
import com.cs.service.IUserService;
import com.cs.service.goods.IgoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class IgoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements IgoodsService {
    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public IPage<Goods> getPage(int currentPage, int pageSize, Goods good) {
        LambdaQueryWrapper<Goods> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        IPage<Goods> page=new Page<>(currentPage,pageSize);
        goodsMapper.selectPage(page,lambdaQueryWrapper);
        return page;
    }

    /**
     * 根据分类查询商品信息 分页
     * @param currentPage
     * @param pageSize
     * @param classify
     * @return
     */
    @Override
    public IPage<Goods> getPageByClassify(int currentPage, int pageSize, String classify) {
        LambdaQueryWrapper<Goods> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Goods::getClassify,classify);
        IPage<Goods> page=new Page<>(currentPage,pageSize);
        goodsMapper.selectPage(page,lambdaQueryWrapper);
        return page;
    }

    /**
     * 根据商品名获取商品 分页
     * @param currentPage
     * @param pageSize
     * @param goodName
     * @return
     */
    @Override
    public IPage<Goods> getPageByGoodName(int currentPage, int pageSize, String goodName) {
        LambdaQueryWrapper<Goods> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.like(Goods::getGoodsName,goodName);
        IPage<Goods> page=new Page<>(currentPage,pageSize);
        goodsMapper.selectPage(page,lambdaQueryWrapper);
        return page;
    }
}
